package com.qpcy.controller;

import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.qpcy.utils.ResponseResult;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import com.qpcy.entity.Banner;
import com.qpcy.service.BannerService;
import org.springframework.web.bind.annotation.RestController;
import java.io.Serializable;
import java.util.List;

/**
 * 轮播图 控制层。
 *
 * @author LENOVO
 * @since 2024-10-19
 */
@RestController
@RequestMapping("/banner")
public class BannerController {

    @Autowired
    private BannerService bannerService;

    /**
     * 获取所有轮播图
     *
     * @return
     */
    @GetMapping("/getAll")
    public ResponseResult getAll() {
        QueryWrapper queryWrapper = QueryWrapper.create().orderBy(Banner::getSort, true);
        return ResponseResult.success(bannerService.list(queryWrapper));
    }

    /**
     * 保存轮播图
     *
     * @param banner
     * @return
     */
    @PostMapping("/save")
    public ResponseResult save(@RequestBody Banner banner) {
        return ResponseResult.success(bannerService.save(banner));
    }

    /**
     * 修改轮播图信息
     *
     * @param banner
     * @return
     */
    @PostMapping("/update")
    public ResponseResult update(@RequestBody Banner banner) {
        return ResponseResult.success(bannerService.updateById(banner));
    }

    /**
     * 删除轮播图
     *
     * @param bannerId
     * @return
     */
    @PostMapping("/delete")
    public ResponseResult delete(int bannerId) {
        return ResponseResult.success(bannerService.removeById(bannerId));
    }

}
